package ylsb.controller;

import org.springframework.beans.factory.annotation.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ylsb.service.*;
import ylsb.model.*;
import ylsb.service.YltpXiangmuService;
import ylsb.service.YltprenyuanfenpeiService;
import ylsb.support.JsonResult;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

@RestController
@RequestMapping("hcjieguo")
public class HcjieguoController {

    @Value("${userfilepath}")
    private String userfilepath;
    @Resource
    Hc45Service hc45Service;
    @Resource
    YltprenyuanfenpeiService ddYltprenyuanfenpeiService;
    @Resource
    YltpXiangmuService ddYltpXiangmuService;
    @Resource
    HcjieguoService ddService;
    @Resource
    YltpuserService ddYltpuserService;
    @Resource
    DailiangchuangxinService ddDailiangchuangxinService;
    @Resource
    ShebeiService ddShebeiService;
    @Resource
    YltpjieguoService ddYltpjieguoService;
    @Resource
    PinpaiguanlianService ddPinpaiguanlianService;
    @Resource
    YiyongyuanzeService ddYiyongyuanzeService;

    public Logger log = LoggerFactory.getLogger(YiyongijieguoController.class);

    @RequestMapping("getjindulist")
    public JsonResult<?> getjindulist(@RequestParam("xiangmuid") String ppxiangmuId,
                                      @RequestParam("xiangmuleixing") String ppxiangmuleixiang) {
        try {
            List<Map<String, Object>> mmJindulist = new ArrayList<>();
            Integer mmTotal = 0;
            if (("12").equals(ppxiangmuleixiang)) {
                mmTotal = ddShebeiService.getShebeiCount(ppxiangmuId);
            } else {
                Integer mmTotalall = hc45Service.getPinguiCount(ppxiangmuId);
                Integer mmpaichu = hc45Service.getPaichuPinguiCount(ppxiangmuId);
                mmTotal=mmTotalall-mmpaichu;
            }
            /*if (ppxiangmuleixiang.equals("8") || ppxiangmuleixiang.equals("9")) {
                mmTotal = ddDailiangchuangxinService.getChuangxinCount(ppxiangmuId);
            }*/

            List<Map<String, Object>> mmUserList = ddYltprenyuanfenpeiService.findRenyuanFenpeiByXiangmuId(ppxiangmuId);
            for (Map<String, Object> ysrenyuanfenpei : mmUserList) {
                Map<String, Object> mmMap = new HashMap<String, Object>();
                String mmUserId = ysrenyuanfenpei.get("userid").toString();
                YltpUser mmuser = ddYltpuserService.findOne(mmUserId);
                String mmUserName = mmuser.getUsername();
                Integer mmpinguishu = 0;
                if (("12").equals(ppxiangmuleixiang)) {
                    mmpinguishu = ddYltpjieguoService.getShebeiResultCount(ppxiangmuId, mmUserId, "1");
                }else {
                    mmpinguishu = ddService.getPinguiResultCount(ppxiangmuId, mmUserId, "1");
                }
                /*if (ppxiangmuleixiang.equals("8") || ppxiangmuleixiang.equals("9")) {
                    mmpinguishu = ddYltpjieguoService.getChuangxinchanpinResultCount(ppxiangmuId, mmUserId, "1");
                } */

                String mmShifoutijiao = "";
                if ("1".equals(ysrenyuanfenpei.get("issubmit").toString())) {
                    mmShifoutijiao = "是";
                } else {
                    mmShifoutijiao = "否";
                }
                mmMap.put("username", mmUserName);
                mmMap.put("pinguishu", mmpinguishu + "/" + mmTotal);
                mmMap.put("shifoutijiao", mmShifoutijiao);
                mmJindulist.add(mmMap);
            }

            return JsonResult.getSuccessResult(mmJindulist);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("shijijieguo/getjindulist:error", e);
            return JsonResult.getErrorResult("shijijieguo/getjindulist:error " + e.getMessage());
        }
    }

    @RequestMapping("submit")
    public JsonResult<?> submit(
            @RequestParam("xiangmuid") String ppxiangmuId,
            @RequestParam("xiangmuleixing") String ppxiangmuleixing,
            @RequestParam("userid") String ppuserId) {
        try {
            List<YltpRenyuanfenpei> list = ddYltprenyuanfenpeiService.findbyUserIDandXiangmuId(ppuserId, ppxiangmuId);
            if (list.size() < 1) {
                return JsonResult.getErrorResult("提交失败，人员-项目分配信息不存在");
            }

            Boolean isQuefenlei=false;
            Boolean isGuochan=false;
            String mmFenleiErr="";
            String mmGuochanErr="";
            List<Map<String, Object>> mmPinzhongList=hc45Service.findPinzhongAll(ppxiangmuId);
            if("24".equals(ppxiangmuleixing)||"25".equals(ppxiangmuleixing)||"27".equals(ppxiangmuleixing)){
                for(Map<String, Object> mmMap:mmPinzhongList){
                    String mmPinzhonxuhao=mmMap.get("zongxuhao").toString();
                    /*List<Map<String, Object>> mmResiltList=hc45Service.findResultBypinzhong(ppxiangmuId,ppuserId,mmPinzhonxuhao);
                    if(mmResiltList.size()==0){
                        isQuefenlei=true;
                        mmFenleiErr=mmFenleiErr+","+"【"+mmPinzhonxuhao+"】";
                    }*/
                    //目录，待选有国产的
                    List<Map<String, Object>> mmGuochanList=hc45Service.findGuochanBypinzhong(ppxiangmuId,mmPinzhonxuhao);
                    //有国产
                    if(mmGuochanList.size()!=0){
                        List<Map<String, Object>> mmResultList=hc45Service.findResultBypinzhong(ppxiangmuId,ppuserId,mmPinzhonxuhao);
                        //有选中的
                        if(mmResultList.size()!=0){
                            //选中待选国产
                            List<Map<String, Object>> mmGuochanResultList=hc45Service.findResultGuochanBypinzhong(ppxiangmuId,ppuserId,mmPinzhonxuhao);
                            //目录中有国产
                            List<Map<String, Object>> mmGuochanmuluList=hc45Service.findGuochanmuluBypinzhong(ppxiangmuId,mmPinzhonxuhao);
                            if(mmGuochanResultList.size()==0&&mmGuochanmuluList.size()==0){
                                isGuochan=true;
                                mmGuochanErr=mmGuochanErr+","+"【"+mmPinzhonxuhao+"】";
                            }
                        }

                    }
                }
            }
          /*  if(isQuefenlei&&("24".equals(ppxiangmuleixing))){
                return JsonResult.getErrorResult("提交失败,品种序号"+mmFenleiErr+"没有勾选。");
            }*/
            if(isGuochan){
                return JsonResult.getErrorResult("提交失败,品种序号"+mmGuochanErr+"没有勾选国产。");
            }

            YltpRenyuanfenpei mmRenyuanfenpei = new YltpRenyuanfenpei();
            mmRenyuanfenpei.setId(list.get(0).getId());
            mmRenyuanfenpei.setUserid(ppuserId);
            mmRenyuanfenpei.setXiangmuid(ppxiangmuId);
            mmRenyuanfenpei.setIssubmit(1);
            return ddYltprenyuanfenpeiService.update(mmRenyuanfenpei) == true ? JsonResult.getSuccessResult("提交成功")
                    : JsonResult.getErrorResult("提交失败");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("hcjieguo/submit:error", e);
            return JsonResult.getErrorResult("hcjieguo/submit:error " + e.getMessage());
        }

    }
    @RequestMapping("submittishi")
    public JsonResult<?> submittishi(
            @RequestParam("xiangmuid") String ppxiangmuId,
            @RequestParam("xiangmuleixing") String ppxiangmuleixing,
            @RequestParam("userid") String ppuserId) {
        try {
            List<YltpRenyuanfenpei> list = ddYltprenyuanfenpeiService.findbyUserIDandXiangmuId(ppuserId, ppxiangmuId);
            if (list.size() < 1) {
                return JsonResult.getErrorResult("提交失败，人员-项目分配信息不存在");
            }

            Boolean isQuefenlei=false;
            String mmFenleiErr="";

            List<Map<String, Object>> mmPinzhongList=hc45Service.findPinzhongAll(ppxiangmuId);

                for(Map<String, Object> mmMap:mmPinzhongList){
                    String mmPinzhonxuhao=mmMap.get("zongxuhao").toString();
                    List<Map<String, Object>> mmResiltList=hc45Service.findResultBypinzhong(ppxiangmuId,ppuserId,mmPinzhonxuhao);
                    if(mmResiltList.size()==0){
                        isQuefenlei=true;
                        mmFenleiErr+="【"+mmPinzhonxuhao+"】";
                    }
                }

            if(isQuefenlei){
                return JsonResult.getSuccessResult(mmFenleiErr);
            }else{
                return JsonResult.getErrorResult("无品种未选");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("hcjieguo/submit:error", e);
            return JsonResult.getErrorResult("hcjieguo/submit:error " + e.getMessage());
        }

    }
    @RequestMapping("getResultCount")
    public JsonResult<?> getResultCount(@RequestParam("xiangmuid") String ppxiangmuId,
                                        @RequestParam("xiangmuleixing") String ppxiangmuleixing,
                                        @RequestParam("userid") String ppuserId) {
        try {
            Integer mmYiTongyishu1 = ddService.getPinguiResultCount("fe218a88-e5e8-408d-9921-ad91f359cd90", ppuserId, "1");
            Integer mmYiTongyishu2 = ddService.getPinguiResultCount("1f65ba47-af7b-401a-a881-b95ec1599358", ppuserId, "1");
            Integer mmYiTongyishu3 = ddService.getPinguiResultCount("55c361c4-a704-49bd-ac6e-7eb734c38001", ppuserId, "1");
            Integer mmYiTongyishu4 = ddService.getPinguiResultCount("d04fa580-8167-4b2a-9391-d59df4647b21", ppuserId, "1");
            Integer mmYiTongyishu5 = ddService.getPinguiResultCount("19e5c4ad-55e1-48ce-bb44-7b824c4ef324", ppuserId, "1");
            Integer mmYiTongyishu6 = ddService.getPinguiResultCount("05cffee2-4e29-4d75-a840-f6dc09fcf95b", ppuserId, "1");
            Integer mmYiTongyishu7 = ddService.getPinguiResultCount("43cef8c8-6f80-461c-a26d-3bbe67efc6b8", ppuserId, "1");
            Integer mmYiTongyishu = mmYiTongyishu1+mmYiTongyishu2+mmYiTongyishu3+mmYiTongyishu4+mmYiTongyishu5+mmYiTongyishu6+mmYiTongyishu7;
/*            Integer mmTongyishu = ddService.getPinguiResultCount(ppxiangmuId, ppuserId, "1");
            Integer mmTotal = hc45Service.getPinguiCount(ppxiangmuId);
            Integer mmpaichu = ddService.getPinpaiResultCount(ppxiangmuId);
            Integer mmTotalpaichu=mmTotal-mmpaichu;
            Integer mmBuTongyishu = mmTotalpaichu - mmTongyishu;*/
            Integer mmTongyishu = 0;
            Integer mmTotal = 0;
            Integer mmBuTongyishu = 0;
            if(ppxiangmuleixing.equals("29")){
                mmTongyishu = ddService.getPinzhongResultCount(ppxiangmuId, ppuserId, "1");
                mmTotal = hc45Service.getPinzhongCount(ppxiangmuId);
                mmBuTongyishu = mmTotal - mmTongyishu;
            }
            if(ppxiangmuleixing.equals("26")||ppxiangmuleixing.equals("28")){
                 mmTongyishu = ddService.getPinguiResultCount(ppxiangmuId, ppuserId, "1");
                 mmTotal = hc45Service.getPinguiCount(ppxiangmuId);
                 mmBuTongyishu = mmTotal - mmTongyishu;
            }
            if(ppxiangmuleixing.equals("24")||ppxiangmuleixing.equals("25")||ppxiangmuleixing.equals("27")){
                 mmTongyishu = ddService.getPinpaiResultCount(ppxiangmuId, ppuserId, "1");
                 mmTotal = hc45Service.getPinpaiCount(ppxiangmuId);
                 mmBuTongyishu = mmTotal - mmTongyishu;
            }
            Map<String, Object> mmMap = new HashMap<String, Object>();
            mmMap.put("yitongyiShu", mmYiTongyishu);
            mmMap.put("tongyiShu", mmTongyishu);
            mmMap.put("butongyiShu", mmBuTongyishu);
            mmMap.put("total", mmTotal);
            return JsonResult.getSuccessResult(mmMap);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("shijijieguo/getResultCount:error", e);
            return JsonResult.getErrorResult("shijijieguo/getResultCount:error " + e.getMessage());
        }
    }

    @RequestMapping("votesure")
    public JsonResult<?> votesure(@RequestParam("xiangmuid") String ppxiangmuid,
//                                  @RequestParam("tiaojian") String pptiaojian,
                                  @RequestParam("userid") String ppuserId) {

        try {

            YltpXiangmu mmxiangmu = ddYltpXiangmuService.findOne(ppxiangmuid);
            if (mmxiangmu.getIsactived() != 1) {
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            List<YltpRenyuanfenpei> mmfenpei = ddYltprenyuanfenpeiService.findbyUserIDandXiangmuId(ppuserId, ppxiangmuid);
            if (mmfenpei.get(0).getIssubmit() == 1) {
                return JsonResult.getErrorResult("表决失败，投票已提交。");
            }
//            if (pptiaojian == null || pptiaojian.isEmpty()) {
//                return JsonResult.getErrorResult("请选择筛选条件。");
//            }
//            String mmleibie = "";
//            String mmpinpaiqingkuang = "";
//            if (pptiaojian.equals("封闭试剂")) {
//                mmleibie = pptiaojian;
//            } else if (pptiaojian.equals("一个品牌")) {
//                mmpinpaiqingkuang = pptiaojian;
//            } else if (pptiaojian.equals("两个品牌")) {
//                mmpinpaiqingkuang = pptiaojian;
//            } else if (pptiaojian.equals("专机专用")) {
//                mmpinpaiqingkuang = pptiaojian;
//            }else{
//                mmleibie=pptiaojian;
//                mmpinpaiqingkuang=pptiaojian;
//            }

//            List<Map<String, Object>> mmList = hc45Service.findAllByXiangmuIdAndTiaojian(ppxiangmuid, mmleibie, mmpinpaiqingkuang);
            List<Map<String, Object>> mmList = hc45Service.findAllByXiangmuIdAndTiaojian(ppxiangmuid);

            if (mmList.size() == 0) {
                return JsonResult.getErrorResult("没有筛选出数据。");
            }
            for (Map<String, Object> mmMap : mmList) {
                String mmDetailId = mmMap.get("id").toString();
                String mmPinzhonxuhao = mmMap.get("pinzhongxuhao").toString();
                String mmPinpaixuhao = mmMap.get("pinpai").toString();
                List<Map<String, Object>> mmjieguoList = ddService.findPinguiJieguo(ppxiangmuid, ppuserId, mmDetailId, mmPinzhonxuhao, mmPinpaixuhao);
                /*List<Map<String, Object>> mmdetailList = ddShijiService.findXinghaoByPinpai(ppxiangmuid, mmPinzhonxuhao, mmPinpaixuhao);
                String mmDetailId = mmdetailList.get(0).get("id").toString();*/
                if (mmjieguoList.size() > 0) {
                    String mmId = mmjieguoList.get(0).get("id").toString();
                    Hcjieguo mmjieguo = ddService.findOne(mmId);
                    mmjieguo.setXiangmuid(ppxiangmuid);
                    mmjieguo.setResult("1");
                    ddService.modify(mmjieguo);
                } else {
                    Hcjieguo mmjieguo = new Hcjieguo();
                    String mmId = UUID.randomUUID().toString();
                    mmjieguo.setId(mmId);
                    mmjieguo.setDetailid(mmDetailId);
                    mmjieguo.setUserid(ppuserId);
                    mmjieguo.setXiangmuid(ppxiangmuid);
                    mmjieguo.setResult("1");
                    mmjieguo.setCreatetime(new Date());
                    mmjieguo.setPinzhong(Integer.parseInt(mmPinzhonxuhao));
                    mmjieguo.setPinpai(mmPinpaixuhao);
                    ddService.add(mmjieguo);
                }

            }

            return JsonResult.getSuccessResult("表决成功");

        } catch (Exception e) {
            e.printStackTrace();
            log.error("shijijieguo/votesure:error", e);
            return JsonResult.getErrorResult("shijijieguo/votesure:error " + e.getMessage());
        }
    }
    @RequestMapping("toupiao")
    public JsonResult<?> toupiao(@RequestParam("xiangmuid") String xiangmuid,
                                 @RequestParam("id") List<String> ppdetailIds,
                                 @RequestParam("pinzhong") int ppPinzhong,
                                 @RequestParam("pinpai") String ppPinpai,
                                 @RequestParam("userid") String ppuserId,
                                 @RequestParam("result") String ppresult) {

        try {
            Hcjieguo mmjieguo = new Hcjieguo();

            YltpXiangmu mmxiangmu = ddYltpXiangmuService.findOne(xiangmuid);
            if (mmxiangmu.getIsactived() != 1) {
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            String mmxiangmuleixing=mmxiangmu.getXiangmuleixing();

            List<YltpRenyuanfenpei> listfenpei = ddYltprenyuanfenpeiService.findbyUserIDandXiangmuId(ppuserId, xiangmuid);
            if (listfenpei.get(0).getIssubmit() == 1) {
                return JsonResult.getErrorResult("表决失败，当前投票项已提交");
            }
           /* if(ddYiyongyuanzeService.checkByUserId(ppPinzhong, ppPinpai,ppuserId,xiangmuid)==null){
                return JsonResult.getErrorResult("表决失败，请先选择适用原则");
            }*/
            int shuliang=0;
            if ("1".equals(ppresult)) {
                boolean mmIsok = false;
                //已经选的待选品牌
                List<Map<String, Object>> mmpinpailist=ddService.mmPinpaiByPinzhongList(xiangmuid, ppuserId,ppPinzhong);
                //品牌中是目录内
                List<Map<String, Object>> mmpinpaimululist=ddService.mmPinpaimuluByPinzhongList(xiangmuid,ppPinzhong);
                if("27".equals(mmxiangmuleixing)){
                    shuliang=mmpinpailist.size();
                }else{
                    shuliang=mmpinpailist.size()+mmpinpaimululist.size();
                }

                int flag = 0;
                //存在已经选过的品牌
                int pinpaishu=0;
                if("24".equals(mmxiangmuleixing)){
                    pinpaishu=2;
                }
                if("25".equals(mmxiangmuleixing)){
                    pinpaishu=3;
                }
                if("27".equals(mmxiangmuleixing)){
                    pinpaishu=1;
                }
                if((mmpinpailist!=null)&&("24".equals(mmxiangmuleixing)||"25".equals(mmxiangmuleixing)||"27".equals(mmxiangmuleixing))){
                    //投票不在已选的品牌里面
                    if(mmpinpailist.stream().noneMatch(x -> x.get("pinpai").toString().equals(ppPinpai))){
                        if (shuliang < pinpaishu )flag=1;
                    }else {
                        flag=1;
                    }
                } else{
                    flag=1;
                }
                if (flag==1 ) {
                for (String mmdetailId : ppdetailIds) {
                    Hcjieguo hcjieguo=ddService.checkexistByUserId(mmdetailId, ppPinzhong, ppPinpai, ppuserId, xiangmuid);
                    if (hcjieguo != null) {
                        String mmId = hcjieguo.getId();
                        mmjieguo.setId(mmId);
                        mmjieguo.setXiangmuid(xiangmuid);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        mmIsok = ddService.modify(mmjieguo);

                    } else {
                        mmjieguo.setId(UUID.randomUUID().toString());
                        mmjieguo.setDetailid(mmdetailId);
                        mmjieguo.setPinzhong(ppPinzhong);
                        mmjieguo.setPinpai(ppPinpai);
                        mmjieguo.setUserid(ppuserId);
                        mmjieguo.setXiangmuid(xiangmuid);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        mmIsok = ddService.add(mmjieguo);
                    }
                }
                return mmIsok == true ? JsonResult.getSuccessResult("表决成功")
                        : JsonResult.getErrorResult("表决失败");
                } else {
                    return JsonResult.getErrorResult("同一品种的品牌同意数量不能超过"+pinpaishu+"条。");
                }

            } else {
                boolean mmIsok = false;
                for (String mmdetailId : ppdetailIds) {
                    Hcjieguo hcjieguo=ddService.checkexistByUserId(mmdetailId, ppPinzhong, ppPinpai, ppuserId, xiangmuid);
                    if (hcjieguo != null) {
                        String mmId = hcjieguo.getId();
                        mmjieguo.setId(mmId);
                        mmjieguo.setXiangmuid(xiangmuid);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        mmIsok = ddService.modify(mmjieguo);
                    } else {
                        mmjieguo.setId(UUID.randomUUID().toString());
                        mmjieguo.setDetailid(mmdetailId);
                        mmjieguo.setPinzhong(ppPinzhong);
                        mmjieguo.setPinpai(ppPinpai);
                        mmjieguo.setUserid(ppuserId);
                        mmjieguo.setXiangmuid(xiangmuid);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        mmIsok = ddService.add(mmjieguo);
                    }
                }
                return mmIsok == true ? JsonResult.getSuccessResult("表决成功")
                        : JsonResult.getErrorResult("表决失败");
            }
        } catch (Exception e) {
            e.printStackTrace();

            /*log.error("shijijieguo/toupiao:error", e);*/
            /* return JsonResult.getErrorResult("shijijieguo/toupiao:error " + e.getMessage());*/
            return JsonResult.getErrorResult("表决失败");
        }
    }

    @RequestMapping("toupiaopinzhong")
    public JsonResult<?> toupiaopinzhong(@RequestParam("xiangmuid") String xiangmuid,
                                 @RequestParam("pinzhong") int ppPinzhong,
                                 @RequestParam("userid") String ppuserId,
                                 @RequestParam("result") String ppresult) {

        try {
            Hcjieguo mmjieguo = new Hcjieguo();

            YltpXiangmu mmxiangmu = ddYltpXiangmuService.findOne(xiangmuid);
            if (mmxiangmu.getIsactived() != 1) {
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }

            List<YltpRenyuanfenpei> listfenpei = ddYltprenyuanfenpeiService.findbyUserIDandXiangmuId(ppuserId, xiangmuid);
            if (listfenpei.get(0).getIssubmit() == 1) {
                return JsonResult.getErrorResult("表决失败，当前投票项已提交");
            }

            boolean mmIsok = false;

            List<Map<String, Object>> mmpinpailist=hc45Service.findPinpaiList(xiangmuid,ppPinzhong);
            for(Map<String, Object> mmMap:mmpinpailist){
                String mmPinpaione=mmMap.get("pinpai").toString();
                List<Map<String,Object>> mmxinghaolist = hc45Service.findXinghaoByPinpai(xiangmuid,ppPinzhong,mmPinpaione);
                for(Map<String, Object> mmMapxinghao:mmxinghaolist){
                    String mmxinghaoone=mmMapxinghao.get("id").toString();
                    Hcjieguo hcjieguo=ddService.checkexistByUserId(mmxinghaoone, ppPinzhong, mmPinpaione, ppuserId, xiangmuid);
                    if (hcjieguo != null) {
                        String mmId = hcjieguo.getId();
                        mmjieguo.setId(mmId);
                        mmjieguo.setXiangmuid(xiangmuid);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        mmIsok = ddService.modify(mmjieguo);
                    } else {
                        mmjieguo.setId(UUID.randomUUID().toString());
                        mmjieguo.setDetailid(mmxinghaoone);
                        mmjieguo.setPinzhong(ppPinzhong);
                        mmjieguo.setPinpai(mmPinpaione);
                        mmjieguo.setUserid(ppuserId);
                        mmjieguo.setXiangmuid(xiangmuid);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        mmIsok = ddService.add(mmjieguo);
                }

                }
            }
            return mmIsok == true ? JsonResult.getSuccessResult("表决成功")
                    : JsonResult.getErrorResult("表决失败");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.getErrorResult("表决失败");
        }
    }
    //  导出某个人员的签字表
    @RequestMapping("qianzibiao")
    public void qianzibiao(HttpServletRequest request, HttpServletResponse response,
                           @RequestParam("xiangmuid") String ppxiangmuid,
                           @RequestParam("xiangmuleixing") String ppxiangmuleixing,
                           @RequestParam("userid") String ppuserid) {
        try {
            ddService.daochuqianzibiao(ppxiangmuid, ppuserid, request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("findHuizongbiaolist")
    public JsonResult<?> findHuizongbiaolist(@RequestParam("xiangmuid") String ppxiangmuid) {
        try {
            return ddService.findHuizongbiaolist(ppxiangmuid);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("jieguo/findHuizongbiaolist:error", e);
            return JsonResult.getErrorResult("jieguo/findHuizongbiaolist:error " + e.getMessage());
        }


    }

    @RequestMapping("huizongbiao")
    public void huizongbiao(HttpServletRequest request, HttpServletResponse response,
                            @RequestParam("xiangmuid") String ppxiangmuid,
                            @RequestParam("xiangmuleixing") String ppxiangmuleixing) {

        ddService.huizongbiao(request, response, ppxiangmuid, ppxiangmuleixing);
    }
}
